home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / language / embedded / mcu11 / mcx11v15.arc / CLKDRIVR.AS < prev    next >
Text File  |  1990-12-08  |  5KB  |  77 lines

  1. *CLKDRIVR.AS
  2. *******************************************************************************
  3. *                                                                             *
  4. *  MCX11 Clock Driver task and Interrupt Service Routine (ISR) for the RTI    *
  5. *  timer of the HC11 chip.                                                    *
  6. *                                                                             *
  7. * This task should be assembled with the source of MCX11 as it is considered  *
  8. * a system task and does not need to clutter up the application code.         *
  9. *                                                                             *
  10. *                         --- N O T I C E ---                                 *
  11. *                                                                             *
  12. * This code assumes that the clock driver is task 1. If your assignment is    *
  13. * different, be sure you make the necessary changes in this module or things  *
  14. * are not going to work.                                                      *
  15. *                                                                             *
  16. *******************************************************************************
  17.  
  18. CLKTASK equ     1                   Clock driver is normally task # 1.
  19.  
  20. clkdrv  clrb                        Use task semaphore for synchronization.
  21.         swi
  22.          FCB   .wait.               Wait for a timer to expire.
  23. tmrdone ldx    ACTIVE               Get the address of the first active timer.
  24.         beq    clkdrv               Make sure there is one.
  25.         ldd    CTOCKS,x             If timer exists, check TOCK count to see
  26. *                                     if it has expired. (count <= 0)
  27.         bgt    clkdrv               If TOCK count > 0, timer hasn't expired.
  28.         ldd    CLINK,x              Timer has expired. Unlink it from active
  29.         std    ACTIVE                timer thread. (ACTIVE <== (NEXT))
  30.         ldd    FREE                 Then put it into the unused timer thread.
  31.         std    CLINK,x                (NEXT <== (FREE), FREE <== (CURRENT))
  32.         stx    FREE
  33.         ldd    CTASK,x              Get waiting task and semaphore numbers.
  34. *** (V1.4) ***
  35.         swi                                                                    |
  36.          FCB   .signal.             In either case, signal the waiting task    |
  37. *                                     that timer has expired.
  38.  
  39.         ldx    CRESET,x             Also get the Cyclic Timer Reset counts.
  40.         bpl    tmrdone              If reset counter >= 0, timer is a one-shot.|
  41.         swi
  42.          FCB   .timer.              Otherwise, time is cyclic and needs to be
  43. *                                     reinserted into the timer thread.
  44.         bra    tmrdone              Then go see if another timer expired too.
  45.  
  46. *******************************************************************************
  47. *                                                                             *
  48. *                      RTI Interrupt Service Routine                          *
  49. *                                                                             *
  50. *******************************************************************************
  51.  
  52. rtiisr  ldaa   #RTIF                Reset the interrupt flag
  53.         staa   TFLG2
  54.         dec    tickcnt              Decrement TICK count to see if TOCK
  55.         beq    tockdon
  56. rtixit  rti                         If not a TOCK, exit quickly.
  57. tockdon ldaa   #TOCK                For a TOCK, reset the TICK count.
  58.         staa   tickcnt
  59.         ldx    ACTIVE               See if there is an active timer.
  60.         beq    rtixit               If not, return immediately.
  61.         ldd    CTOCKS,x             Decrement the TOCK count
  62.         subd   #1                   If timer didn't expire, quick exit.
  63.         std    CTOCKS,x
  64.         bne    rtixit
  65.         tst    intlvl               Here we have an expired timer. Test the
  66.         bne    cnotl1                 interrupt nest level. branch if not lvl 1
  67.         tst    curtsk               If level 1, test if Dispatcher was
  68.         beq    cnotl1                 interrupted. If so, treat as system.
  69.         ldx    curtcb               If a task was interrupted, get its TCB
  70.         sts    ACTSP,x                address and save the stack pointer.
  71.         lds    #SYSTACK             Set up system stack pointer.
  72. cnotl1  inc    intlvl               Bump interrupt nest level.
  73.         cli                         Enable interrupts.
  74.         ldab   #NNAMSEM+CLKTASK     Set up task semaphore # for clock driver.
  75.         jmp    isrrtn               Do a context switch to clock driver.
  76.  
  77.